<template>
  <!-- 登录 -->
  <div class="signin">
    <div class="signin-header">
      <div class="signin-header-title">
        <HeaderLogo />
      </div>
    </div>
    <div class="signin-content">
      <div class="signin-content-illustration">
        <SvgSignIn />
      </div>
      <div class="signin-content-form">
        <div class="signin-content-form-title">
          <p>{{ t('login.title') }}</p>
          <p>
            <span>{{ t('login.noAccount') }}</span>
            <el-button type="text" @click="handleSignUp">{{ t('login.signUpNow') }}</el-button>
          </p>
        </div>
        <div class="signin-content-form-input">
          <el-form :model="ruleForm" :rules="rules" ref="formRef" size="large">
            <el-form-item label="" prop="username">
              <p class="signin-content-form-input-label">{{ t('login.username') }}</p>
              <el-input v-model="ruleForm.username" />
            </el-form-item>
            <el-form-item label="" prop="password">
              <p class="signin-content-form-input-label">{{ t('login.password') }}</p>
              <el-input v-model="ruleForm.password" show-password />
            </el-form-item>
            <el-form-item>
              <div class="signin-content-form-input-support">
                <el-checkbox v-model="ruleForm.remember">
                  {{ t('login.remember') }}
                </el-checkbox>
                <el-button type="primary" link @click="handleForgetPassword">{{
                  t('login.forgetPassword')
                }}</el-button>
              </div>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleSignIn" style="width: 100%">{{
                t('login.signIn')
              }}</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import SvgSignIn from '../svg/SvgSignIn.vue';
import HeaderLogo from '@/components/Header/HeaderLogo.vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { ref } from 'vue';
import type { FormInstance } from 'element-plus';
defineOptions({
  name: 'SignIn',
});
const { t } = useI18n();
const router = useRouter();
const formRef = ref<FormInstance>();
const ruleForm = ref({
  username: '', // 用户名
  password: '', // 密码
  remember: false, // 记住我
});
const rules = ref({
  username: [{ required: true, message: t('login.usernameRequired'), trigger: 'blur' }],
  password: [{ required: true, message: t('login.passwordRequired'), trigger: 'blur' }],
});
// 点击注册
const handleSignUp = () => {
  router.push('/register');
};
// 点击登录
const handleSignIn = () => {
  formRef.value?.validate((valid) => {
    if (valid) {
      console.log('submit!');
    }
  });
};
// 点击忘记密码
const handleForgetPassword = () => {
  console.log('forgetPassword');
};
</script>
<style lang="scss" scoped>
.signin {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background-color: rgba(106, 75, 255, 0.03);
  &:before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 200vh;
    height: 200vh;
    border-radius: 50%;
    background-color: #171725;
    transform: translate(50%, -25%);
    z-index: 1;
  }
  &-header {
    width: 100%;
    height: 108px;
    display: flex;
    align-items: center;
    padding: 0 32px;
    box-sizing: border-box;
  }
  &-content {
    width: 100%;
    height: calc(100% - 108px);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    &-illustration {
      width: 50%;
    }
    &-form {
      width: 484px;
      display: flex;
      flex-direction: column;
      align-items: center;
      &-title {
        width: 100%;
        letter-spacing: 4px;
        margin-bottom: 30px;
        p:first-child {
          font-size: 32px;
          font-weight: 600;
          margin-bottom: 16px;
        }
        p:last-child {
          font-size: 16px;
          font-weight: 400;
        }
      }
      &-input {
        width: 100%;
        &-label {
          font-size: 16px;
          font-weight: 400;
          margin-bottom: 8px;
        }
        &-support {
          width: 100%;
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
      }
    }
  }
}
</style>
